<?php
/*
 * FastSHL                              | Universal Syntax HighLighter |
 * ---------------------------------------------------------------------

   Copyright (C) 2002-2004  Juraj 'hvge' Durech

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
   
 * ---------------------------------------------------------------------
 * RUBY - SHL Language File
 *
 * Changes:
 *  V0.01	created
 *  V0.02	added some highlighting support
 *  V0.03	stolen keywords from geshi ruby-lang file
 *  V0.04       added some other highlighting support
 * 
 * Known Issues:
 *  __FILE__ gets parsed as a CONST, not keyword
 *  object.nil? (nil) gets parsed as a keyword
 *  doesn't do %w{..} or %q@...@
 *  doesn't do HEREDOC
 * 
 * 
 * 
 */
class RUBY_lang
{
	var $states;
	var $initial_state;
	var $keywords;
	var $version;
	var $signature;

	function RUBY_lang()
	{
		$this->signature = "SHL";
		$this->version = "0.03";
		$this->initial_state = "OUT";
		$this->states = array(
		
			"OUT" => array (
				array(
						"//" => array("COMMENT1",0),
						"#" => array("COMMENT1",0),
						"%>" => array("_QUIT",0),
						"@@" => array("VAR_STATIC",0),
						"@" => array("VAR",0),
						"." =>  array("DOT_OPERATOR",0),
						":" => array("SYMBOL",0),
						"/" => array("REGEXP",0),
						"`" => array("INTERPOLATION",0),
						'"' => array("QUOTE",0),
						'{' => array("BLOCK",0),
						"'" => array("QUOTE1",0),
						"+" => array("OPERATOR",0),
						"=>" => array("OPERATOR",0),
						"=" => array("ASSIGN_OPERATOR",0),
						"def " => array("DEF",0),
						'do ' => array("DO",0),
						"$" => array("GLOBAL_VAR",0),
						"\n=begin" => array("COMMENT",0) ,
						"PHP_DELIM" => array("OUT",1),
						'class ' => array("CLASS_DEF",0),
						"ALPHA" => array("FUNCTION_CALL",-1),		// -1 - char back to stream
						"NUMBER" => array("NUM",0),
						),
				PF_KEYWORD,
				null,											// null = "normal"
				null),


			"CLASS_DEF" => array(
				array(
                                   		"ALPHA" => array("CLASS_NAME",0),
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-k1",									
				null), 

			"CLASS_NAME" => array(
				array(
                                   		"ALPHANUM" => array("CLASS_NAME",0),
                                   		"::" => array("CLASS_NAME_NAMESPACE",0),
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-class_name",									
				null), 

			"CLASS_NAME_NAMESPACE" => array(
				array(
                                   		"ALPHANUM" => array("CLASS_NAME_NAMESPACE",0),
                                   		"::" => array("CLASS_NAME_NAMESPACE",0),
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-class_name_namespace",									
				null), 

			
			# def ...
			"DEF" => array(
				array(
                                   		"ALPHA" => array("DEF_FUNCTION_NAME",0),
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-k1",									
				null),
			# (def) fnc_name
			"DEF_FUNCTION_NAME" => array(
				array(
						" " => array("DEF_FUNCTION_ARGS",0),
						"!SAFECHAR" => array("_RET",1),
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-fun",									
				null),

			# (def fnc_name) <args>
                       "DEF_FUNCTION_ARGS" => array(
				array(
						"ALPHA" => array("FNC_ARG",-1),
						"\n" => array("OUT",1), #docasny hack/fix poskoceni radkovani o 3 radky
						),
				PF_KEYWORD | PF_RECURSION,
				null,									
				null),
			
			# (def fnc_name) arg1(, )arg2
			"FNC_ARG" => array(
				array(
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				'rb-f_arg',									
				null),


			
			"DO" => array(
				array(
                                   		' ' => array("DO",0),
                                   		'|' => array("BLOCK_ARGS",0),
						"ALPHA" => array("FUNCTION_CALL",-1),
						"!SAFECHAR" => array("_RET",1),
						"SAFECHAR" => array("_RET",1),
						"\n" => array("_RET",1),
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-k1",									
				null),
			
			"BLOCK" => array(
				array(
                                   		' ' => array("DO",0),
                                   		'|' => array("BLOCK_ARGS",0),
						"!SAFECHAR" => array("_RET",1),
						"\n" => array("_RET",1),
						),
				PF_KEYWORD | PF_RECURSION,
				null,
				null),
			
			"BLOCK_ARGS" => array(
				array(
						"|" =>  array("_RET",0),
						"ALPHA" =>  array("BLOCK_ARG",0),
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-block",									
				null),

			"BLOCK_ARG" => array(
				array(
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-block_arg",									
				null),

			"FUNCTION_CALL" => array(
				array(
						"." =>  array("DOT_OPERATOR",0),
						#"[" =>  array("ARRAY_OPERATOR",0),
						"!SAFECHAR" =>  array("_RET",-1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-fun",									
				null),

			"ARRAY_OPERATOR" => array(
				array(
						"ALPHA" =>  array("FUNCTION_CALL",-1),
						":" =>  array("SYMBOL",0),
						"@" =>  array("VAR",0),
						"@@" =>  array("VAR_STATIC",0),
						"$" =>  array("GLOBAL_VAR",0),
						"]" =>  array("_RET",-1)
						),
				PF_KEYWORD | PF_RECURSION,
				"null",									
				null),

			"METH_CALL" => array(
				array(
						" " =>  array("_RET",-1),
						"(" =>  array("_RET",-1),
						"." =>  array("DOT_OPERATOR",0),
						"?" =>  array("METH_CALL",0),
						"!" =>  array("METH_CALL",0),
						"!SAFECHAR" =>  array("_RET",-1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-meth",
				null),

			"DOT_OPERATOR" => array(
				array(
						"ALPHA" =>  array("METH_CALL",-1),
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-op",									
				null),

			"ASSIGN_OPERATOR" => array(
				array(
						"!SAFECHAR" => array("_RET",1),
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-as",									
				null),

			"OPERATOR" => array(
				array(
						"!NUMBER" => array("_RET",1),
						"NUMBER" => array("_RET",1),
						),
				PF_KEYWORD | PF_RECURSION,
				"rb-op",									
				null),

                       "NORMAL" => array(
				array(
						"!SAFECHAR" => array("_RET",1)
						),
				PF_KEYWORD | PF_RECURSION,
				null,									
				null),
			
			//rekurzivna implementacia komentarov	
			"COMMENT" => array(
				array(
						"=end" => array("_RET",0),
						"_COUNTAB" => array("COMMENT",0),
						),
				PF_RECURSION,
				"rb-ml_c",
				null),

			"COMMENT1" => array(
				array(
						"\n" => array("_RET",0),
						"%>" => array("_RET",-1),
						"_COUNTAB" => array("COMMENT1",0),
						),
				PF_RECURSION,
				"rb-c",
				null),	
			
			"GLOBAL_VAR" => array(
				array(
						"!SAFECHAR" => array("_RET",1)	
						),
				PF_RECURSION,
				"rb-gl_var",
				null),

			"VAR" => array(
				array(
						"!SAFECHAR" => array("_RET",1)	
						),
				PF_RECURSION,
				"rb-attr",
				null),

			"VAR_STATIC" => array(
				array(
						"!SAFECHAR" => array("_RET",1)	
						),
				PF_RECURSION,
				"rb-st_attr",
				null),
                   
			"SYMBOL" => array(
				array(
						#"." => array("VAR",0),
						"!SAFECHAR" => array("_RET",1)
						),
				PF_RECURSION,
				"rb-s",
				null),
                   
			//rekurzivna implementacia stringu
			"REGEXP" => array(
				array(
						'\\\\' => array("REGEXP",0),
						'\/' => array("REGEXP",0),
						'/' => array("_RET",0),
						),
				PF_RECURSION,
				"rb-regexp",
				null),

			"INTERPOLATION" => array(
				array(
						'\\\\' => array("INTERPOLATION",0),
						'\`' => array("INTERPOLATION",0),
						'`' => array("_RET",0),
						),
				PF_RECURSION,
				"rb-interpolation",
				null),

			"QUOTE" => array(
				array(
						'#{' => array("VAR_IN_QUOTE",0),
						'\\\\' => array("QUOTE",0),
						'\"' => array("QUOTE",0),
						'"' => array("_RET",0),
						),
				PF_RECURSION,
				"rb-dq",
				null),

			"VAR_IN_QUOTE" =>  array(
				array(
						'}' => array("_RET",0),
						),
				PF_RECURSION,
				"rb-in_q",
				null),

			"QUOTE1" => array(
				array(
						"\'" => array("QUOTE1",0),
						"'" => array("_RET",0)
						),
				PF_RECURSION,
				"rb-q",
				null),

			//rekurzivna implementacia cisla
			"NUM" => array(
				array(
						"x" => array("HEX_NUM",0),
						"NUMBER" => array("DEC_NUM",0),
						"!NUMBER" => array("_RET",1)	//char back to stream
						),
				PF_RECURSION,
				"rb-n",
				null),

			"DEC_NUM" => array(
				array(
						"!NUMBER" => array("_RET",1)	//char back to stream
						),
				0,
				"rb-n",
				null),


			"HEX_NUM" => array(
				array(
						"!HEXNUM" => array("_RET",1)	//char back to stream
						),
				0,
				"rb-hex_n",
				null),

			"_QUIT" => array (null, PF_NEWLANG, "xlang", /* =style*/ "", /* =new language*/)

		);

		
		$this->keywords = array(
			"rb-k",

          array_merge(

               # keywords

              array_fill_keys(array(
                  'alias', 'and', 'begin', 'break', 'case', 'class',
                  'def', 'defined', /*'do',*/ 'else', 'elsif', 'end',
                  'ensure', 'for', 'if', 'in', 'module', 'while',
                  'next', 'not', 'or', 'redo', 'rescue', 'yield',
                  'retry', 'super', 'then', 'undef', 'unless',
                  'until', 'when', 'BEGIN', 'END', 'include',

                  '__FILE__', '__LINE__', 'false', 'nil', 'self', 'true',
                  'return',

                  'Array', 'Float', 'Integer', 'String', 'at_exit',
                  'autoload', 'binding', 'caller', 'catch', 'chop', 'chop!',
                  'chomp', 'chomp!', 'eval', 'exec', 'exit', 'exit!', 'fail',
                  'fork', 'format', 'gets', 'global_variables', 'gsub', 'gsub!',
                  'iterator?', 'lambda', 'load', 'local_variables', 'loop',
                  'open', 'p', 'print', 'printf', 'proc', 'putc', 'puts',
                  'raise', 'rand', 'readline', 'readlines', 'require', 'select',
                  'sleep', 'split', 'sprintf', 'srand', 'sub', 'sub!', 'syscall',
                  'system', 'trace_var', 'trap', 'untrace_var'),
                  1
               ),

               # special classes

               array_fill_keys(array(
                  'Abbrev', 'ArgumentError', 'Base64', 'Benchmark',
                  'Benchmark::Tms', 'Bignum', 'Binding', 'CGI', 'CGI::Cookie',
                  'CGI::HtmlExtension', 'CGI::QueryExtension',
                  'CGI::Session', 'CGI::Session::FileStore',
                  'CGI::Session::MemoryStore', 'Class', 'Comparable', 'Complex',
                  'ConditionVariable', 'Continuation', 'Data',
                  'Date', 'DateTime', 'Delegator', 'Dir', 'EOFError', 'ERB',
                  'ERB::Util', 'Enumerable', 'Enumerable::Enumerator', 'Errno',
                  'Exception', 'FalseClass', 'File',
                  'File::Constants', 'File::Stat', 'FileTest', 'FileUtils',
                  'FileUtils::DryRun', 'FileUtils::NoWrite',
                  'FileUtils::StreamUtils_', 'FileUtils::Verbose', 'Find',
                  'Fixnum', 'FloatDomainError', 'Forwardable', 'GC', 'Generator',
                  'Hash', 'IO', 'IOError', 'Iconv', 'Iconv::BrokenLibrary',
                  'Iconv::Failure', 'Iconv::IllegalSequence',
                  'Iconv::InvalidCharacter', 'Iconv::InvalidEncoding',
                  'Iconv::OutOfRange', 'IndexError', 'Interrupt', 'Kernel',
                  'LoadError', 'LocalJumpError', 'Logger', 'Logger::Application',
                  'Logger::Error', 'Logger::Formatter', 'Logger::LogDevice',
                  'Logger::LogDevice::LogDeviceMutex', 'Logger::Severity',
                  'Logger::ShiftingError', 'Marshal', 'MatchData',
                  'Math', 'Matrix', 'Method', 'Module', 'Mutex', 'NameError',
                  'NameError::message', 'NilClass', 'NoMemoryError',
                  'NoMethodError', 'NotImplementedError', 'Numeric', 'Object',
                  'ObjectSpace', 'Observable', 'PStore', 'PStore::Error',
                  'Pathname', 'Precision', 'Proc', 'Process', 'Process::GID',
                  'Process::Status', 'Process::Sys', 'Process::UID', 'Queue',
                  'Range', 'RangeError', 'Rational', 'Regexp', 'RegexpError',
                  'RuntimeError', 'ScriptError', 'SecurityError', 'Set',
                  'Shellwords', 'Signal', 'SignalException', 'SimpleDelegator',
                  'SingleForwardable', 'Singleton', 'SingletonClassMethods',
                  'SizedQueue', 'SortedSet', 'StandardError', 'StringIO',
                  'StringScanner', 'StringScanner::Error', 'Struct', 'Symbol',
                  'SyncEnumerator', 'SyntaxError', 'SystemCallError',
                  'SystemExit', 'SystemStackError', 'Tempfile',
                  'Test::Unit::TestCase', 'Test::Unit', 'Test', 'Thread',
                  'ThreadError', 'ThreadGroup',
                  'ThreadsWait', 'Time', 'TrueClass', 'TypeError', 'URI',
                  'URI::BadURIError', 'URI::Error', 'URI::Escape', 'URI::FTP',
                  'URI::Generic', 'URI::HTTP', 'URI::HTTPS',
                  'URI::InvalidComponentError', 'URI::InvalidURIError',
                  'URI::LDAP', 'URI::MailTo', 'URI::REGEXP',
                  'URI::REGEXP::PATTERN', 'UnboundMethod', 'Vector', 'YAML',
                  'ZeroDivisionError', 'Zlib',
                  'Zlib::BufError', 'Zlib::DataError', 'Zlib::Deflate',
                  'Zlib::Error', 'Zlib::GzipFile', 'Zlib::GzipFile::CRCError',
                  'Zlib::GzipFile::Error', 'Zlib::GzipFile::LengthError',
                  'Zlib::GzipFile::NoFooter', 'Zlib::GzipReader',
                  'Zlib::GzipWriter', 'Zlib::Inflate', 'Zlib::MemError',
                  'Zlib::NeedDict', 'Zlib::StreamEnd', 'Zlib::StreamError',
                  'Zlib::VersionError',
                  'Zlib::ZStream',
                  'Enumerable',
                  'HTML::Selector', 'HashWithIndifferentAccess', 'Inflector',
                  'Inflector::Inflections', 'Mime', 'Mime::Type',
                  'OCI8AutoRecover', 'Symbol', 'TimeZone', 'XmlSimple'),
                  2
                  )
                )
             );
	}
}

